import Vue from 'vue'

// 声明一个对象
const directivesObj = {
  errorImg: {
    // 指令周期
    inserted(dom, obj) {
      dom.src = dom.src || obj.value || require('@/assets/common/person.png')
      dom.onerror = () => {
        dom.src = obj.value || require('@/assets/common/person.png')
      }
    },
    componentUpdated(dom, obj) {
      dom.src = dom.src || obj.value || require('@/assets/common/person.png')
      dom.onerror = () => {
        dom.src = obj.value || require('@/assets/common/person.png')
      }
    }
  }
}

Object.entries(directivesObj).forEach((item) => {
  Vue.directive(item[0], item[1])
})
